/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"8000F86D-A3D1-4FD5-A976-A65EF30509D0"}
 */
var pass = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"1F252BEB-EA04-4839-B081-77CB02A61393"}
 */
var pass2 = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"0FDCBB48-7620-448E-AF26-F9AC06B3CD71"}
 * @AllowToRunInFind
 */
function grabar(event) {
	var fs = databaseManager.getFoundSet('fwk_navigation_infocom','usuarios')
	
	fs.loadAllRecords()
	fs.find()
	fs.documento = documento
	var cant = fs.search()
	
	if (cant == 1)
		globals.gDialog('Error','Ya existe un usuario con ese numero de documento','OK','CerrarForm')
	else
	{
		if (pass == pass2)
		{
			var usr = security.createUser( usuario,  pass)
			if (usr == null)
				globals.gDialog('Error','Error al crear usuario','OK','CerrarForm')
			else
			{
				security.addUserToGroup(usr, 'Usuario')
				hash_pass = globals.hashPass(pass)
				pass = null
				pass2 = null
				databaseManager.saveData()
				globals.gDialog('Exito','Usuario creado exitosamente','OK','CerrarForm')
			}
		}
		else
		{
			pass = null
			pass2 = null
			globals.gDialog('Error','Verificacion de contraseña fallo','OK','CerrarForm')
		}	
	}
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"81BBDBC1-8BB8-4A00-AB98-F59C13ED652F"}
 */
function onShowForm(firstShow, event) {
	controller.newRecord()
}
